package coupon

import (
	// "bp/cache"
	sqlc "bp/db/sqlc"
	// "bp/internal/util"
	"context"
)

// CheckHasAnyCouponSnCanGotParam 聚合券投放统计记录参数
type CheckHasAnyCouponSnCanGotParam struct {
	CouponPtr       *sqlc.Coupon
	Issuer          string
	DistributeScene string
}

// CheckHasAnyCouponSnCanGot 指定券投放平台+场景下是否有可领取的sn
func (s *CouponEntityServiceImp) CheckHasAnyCouponSnCanGot(ctx context.Context, q *sqlc.Queries, ptr *CheckHasAnyCouponSnCanGotParam) (checkRet bool, err error) {
	// slog := util.NewContextLogger(ctx, s.slog)
	aggRet, err := q.AggCouponDistributionStatsByCouponIDAndIssuerAndDistributeScene(ctx, sqlc.AggCouponDistributionStatsByCouponIDAndIssuerAndDistributeSceneParams{
		CouponID:        ptr.CouponPtr.ID,
		Issuer:          ptr.Issuer,
		DistributeScene: ptr.DistributeScene,
	})
	if err != nil {
		return
	}
	checkRet = aggRet.DistributedCnt-aggRet.GotCnt > 0
	return
}
